Description: <short summary of the patch>
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 opennebula (5.0.2-2) unstable; urgency=low
 .
   * Imported from http://packages.qa.debian.org/o/opennebula.html
Author: OpenNebula Team <contact@opennebula.org>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- /dev/null
+++ opennebula-5.0.2/90de031812966f61240ab1e0de3f22d3d24b0f5d.patch
@@ -0,0 +1,138 @@
+From d23ee23f75aafa0ec6c6d4ab5a621e763b93eefe Mon Sep 17 00:00:00 2001
+From: "Ruben S. Montero" <rsmontero@opennebula.org>
+Date: Fri, 2 Sep 2016 13:58:33 +0200
+Subject: [PATCH] Do not update disk monitor infor in the DB. Disk usage will
+ be kept in the object and written to the DB the next time the VM is updated
+ (presumably, in the next monitor message from probes). This will reduce DB
+ I/O needs
+
+(cherry picked from commit 9c929148fcda3c261aeb42d1440573473704bd0e)
+---
+ include/VirtualMachineManagerDriver.h  |  7 +++++--
+ src/im/MonitorThread.cc                |  2 +-
+ src/image/ImageManagerDriver.cc        |  2 +-
+ src/vmm/VirtualMachineManagerDriver.cc | 25 ++++++++++++++++---------
+ 4 files changed, 23 insertions(+), 13 deletions(-)
+
+diff --git a/include/VirtualMachineManagerDriver.h b/include/VirtualMachineManagerDriver.h
+index c32b57c..c18e9ad 100644
+--- a/include/VirtualMachineManagerDriver.h
++++ b/include/VirtualMachineManagerDriver.h
+@@ -74,16 +74,19 @@ public:
+      *
+      * @param id VM id
+      * @param monitor_str String returned by the poll driver call
++     * @param update_db write data to DB (or keep it in memory)
+      */
+-    static void process_poll(int id, const string &monitor_str);
++    static void process_poll(int id, const string &monitor_str, bool update_db);
+ 
+     /**
+      * Updates the VM with the information gathered by the drivers
+      *
+      * @param vm VM to update, must be locked
+      * @param monitor_str String returned by the poll driver call
++     * @param update_db write data to DB (or keep it in memory)
+      */
+-    static void process_poll(VirtualMachine* vm, const string &monitor_str);
++    static void process_poll(VirtualMachine* vm, const string &monitor_str,
++        bool update_db);
+ 
+     /**
+      *  Check if action is supported for imported VMs
+diff --git a/src/im/MonitorThread.cc b/src/im/MonitorThread.cc
+index e79a896..9f2e2be 100644
+--- a/src/im/MonitorThread.cc
++++ b/src/im/MonitorThread.cc
+@@ -282,7 +282,7 @@ void MonitorThread::do_message()
+                 continue;
+             }
+ 
+-            VirtualMachineManagerDriver::process_poll(vm, itm->second);
++            VirtualMachineManagerDriver::process_poll(vm, itm->second, true);
+ 
+             vm->unlock();
+         }
+diff --git a/src/image/ImageManagerDriver.cc b/src/image/ImageManagerDriver.cc
+index 64cc412..4770268 100644
+--- a/src/image/ImageManagerDriver.cc
++++ b/src/image/ImageManagerDriver.cc
+@@ -706,7 +706,7 @@ static void monitor_action(istringstream& is,
+             continue;
+         }
+ 
+-        VirtualMachineManagerDriver::process_poll(vm_id, poll_info);
++        VirtualMachineManagerDriver::process_poll(vm_id, poll_info, false);
+     }
+ 
+     oss << "Datastore " << ds_name << " (" << id << ") successfully monitored.";
+diff --git a/src/vmm/VirtualMachineManagerDriver.cc b/src/vmm/VirtualMachineManagerDriver.cc
+index de51da7..1ffcaa7 100644
+--- a/src/vmm/VirtualMachineManagerDriver.cc
++++ b/src/vmm/VirtualMachineManagerDriver.cc
+@@ -645,7 +645,7 @@ void VirtualMachineManagerDriver::protocol(const string& message) const
+             string monitor_str;
+             getline(is, monitor_str);
+ 
+-            process_poll(vm, monitor_str);
++            process_poll(vm, monitor_str, true);
+         }
+         else
+         {
+@@ -670,7 +670,8 @@ void VirtualMachineManagerDriver::protocol(const string& message) const
+ 
+ void VirtualMachineManagerDriver::process_poll(
+         int id,
+-        const string &monitor_str)
++        const string &monitor_str,
++        bool update_db)
+ {
+     // Get the VM from the pool
+     VirtualMachine* vm = Nebula::instance().get_vmpool()->get(id,true);
+@@ -680,7 +681,7 @@ void VirtualMachineManagerDriver::process_poll(
+         return;
+     }
+ 
+-    process_poll(vm, monitor_str);
++    process_poll(vm, monitor_str, update_db);
+ 
+     vm->unlock();
+ }
+@@ -690,7 +691,8 @@ void VirtualMachineManagerDriver::process_poll(
+ 
+ void VirtualMachineManagerDriver::process_poll(
+         VirtualMachine* vm,
+-        const string&   monitor_str)
++        const string&   monitor_str,
++        bool            update_db)
+ {
+     char state;
+ 
+@@ -705,14 +707,19 @@ void VirtualMachineManagerDriver::process_poll(
+ 
+     if (vm->get_state() == VirtualMachine::ACTIVE)
+     {
+-        if (vm->update_info(monitor_str) == 0)
++        int rc = vm->update_info(monitor_str);
++
++        if ( update_db )
+         {
+-            vmpool->update_history(vm);
++            if ( rc == 0)
++            {
++                vmpool->update_history(vm);
+ 
+-            vmpool->update_monitoring(vm);
+-        }
++                vmpool->update_monitoring(vm);
++            }
+ 
+-        vmpool->update(vm);
++            vmpool->update(vm);
++        }
+ 
+         VirtualMachineMonitorInfo &minfo = vm->get_info();
+ 
+-- 
+2.9.3
+
--- opennebula-5.0.2.orig/include/VirtualMachineManagerDriver.h
+++ opennebula-5.0.2/include/VirtualMachineManagerDriver.h
@@ -74,17 +74,19 @@ public:
      *
      * @param id VM id
      * @param monitor_str String returned by the poll driver call
+     * @param update_db write data to DB (or keep it in memory)
      */
-    static void process_poll(int id, const string &monitor_str);
+    static void process_poll(int id, const string &monitor_str, bool update_db);
 
     /**
      * Updates the VM with the information gathered by the drivers
      *
      * @param vm VM to update, must be locked
      * @param monitor_str String returned by the poll driver call
+     * * @param update_db write data to DB (or keep it in memory)
      */
-    static void process_poll(VirtualMachine* vm, const string &monitor_str);
-
+     static void process_poll(VirtualMachine* vm, const string &monitor_str,
+             bool update_db);
     /**
      *  Check if action is supported for imported VMs
      *    @param action
--- opennebula-5.0.2.orig/src/im/MonitorThread.cc
+++ opennebula-5.0.2/src/im/MonitorThread.cc
@@ -282,7 +282,7 @@ void MonitorThread::do_message()
                 continue;
             }
 
-            VirtualMachineManagerDriver::process_poll(vm, itm->second);
+            VirtualMachineManagerDriver::process_poll(vm, itm->second, true);
 
             vm->unlock();
         }
--- opennebula-5.0.2.orig/src/image/ImageManagerDriver.cc
+++ opennebula-5.0.2/src/image/ImageManagerDriver.cc
@@ -706,7 +706,7 @@ static void monitor_action(istringstream
             continue;
         }
 
-        VirtualMachineManagerDriver::process_poll(vm_id, poll_info);
+        VirtualMachineManagerDriver::process_poll(vm_id, poll_info, false);
     }
 
     oss << "Datastore " << ds_name << " (" << id << ") successfully monitored.";
--- opennebula-5.0.2.orig/src/vmm/VirtualMachineManagerDriver.cc
+++ opennebula-5.0.2/src/vmm/VirtualMachineManagerDriver.cc
@@ -645,7 +645,7 @@ void VirtualMachineManagerDriver::protoc
             string monitor_str;
             getline(is, monitor_str);
 
-            process_poll(vm, monitor_str);
+            process_poll(vm, monitor_str, true);
         }
         else
         {
@@ -670,7 +670,8 @@ void VirtualMachineManagerDriver::protoc
 
 void VirtualMachineManagerDriver::process_poll(
         int id,
-        const string &monitor_str)
+        const string &monitor_str,
+        bool update_db)
 {
     // Get the VM from the pool
     VirtualMachine* vm = Nebula::instance().get_vmpool()->get(id,true);
@@ -680,7 +681,7 @@ void VirtualMachineManagerDriver::proces
         return;
     }
 
-    process_poll(vm, monitor_str);
+    process_poll(vm, monitor_str, update_db);
 
     vm->unlock();
 }
@@ -690,7 +691,8 @@ void VirtualMachineManagerDriver::proces
 
 void VirtualMachineManagerDriver::process_poll(
         VirtualMachine* vm,
-        const string&   monitor_str)
+        const string&   monitor_str,
+        bool            update_db)
 {
     char state;
 
@@ -705,14 +707,18 @@ void VirtualMachineManagerDriver::proces
 
     if (vm->get_state() == VirtualMachine::ACTIVE)
     {
-        if (vm->update_info(monitor_str) == 0)
+        int rc = vm->update_info(monitor_str);
+
+        if ( update_db )
         {
+          if ( rc == 0)
+          {
             vmpool->update_history(vm);
 
             vmpool->update_monitoring(vm);
-        }
-
-        vmpool->update(vm);
+          }
+          vmpool->update(vm);
+          }     
 
         VirtualMachineMonitorInfo &minfo = vm->get_info();
 
